#include <stdio.h>
#include <string.h>


// i am from nanjing

// gnijnan morf ma i

// nanjing from am i

void Exchange(char *str, int len)
{
    for(int i=0;i<len/2;i++)
    {
        char temp = str[i];
        str[i] = str[len-i-1];
        str[len - i -1] = temp;
    }
}

void Exchange2(char *str,int len)
{ 
    int size = 0;
    for(int i = 0; i < len; i++)
    {
        if( str[i] == ' ' || str[i] == '\0' )
        {
           Exchange(str + i-size,size);
           size = 0;
        }
        else
        {
            size ++;
        }
    }
}
int main()
{
    char str[] = "i am from nanjing";
    Exchange(str,strlen(str));
    Exchange2(str,strlen(str));
    printf("%s\n",str);
    return 0;
}
